package cn.clickmed.certification;

import java.text.SimpleDateFormat;

import cn.com.jit.mctk.cert.pojo.CertEntry;

import android.annotation.SuppressLint;

public class SelectCertItem {
	private CertEntry certEntry = null;

	public SelectCertItem() {
		this.certEntry = null;
	}

	public SelectCertItem(CertEntry certEntry) {
		this.certEntry = certEntry;
	}

	public CertEntry getCertEntry() {
		return certEntry;
	}

	public String getSubject() {
		if (certEntry == null)
			return "无证书";
		String strTemp = certEntry.getSubject();
		// int pos = 0;
		// String[] strTemps = strTemp.split(",");
		// for ( int x = 0; x < strTemps.length; x++ ) {
		// if ( (pos = strTemps[x].toUpperCase().indexOf("CN=")) != -1 ) {
		// strTemp = strTemps[x].substring(pos+3);
		// break;
		// }
		// }
		return strTemp;
	}

	public String getSerialNum() {
		if (certEntry == null)
			return "";
		String serialNum = certEntry.getSerialNumber().toString();
		return "序列号：" + serialNum;
	}

	public String getIssuer() {
		if (certEntry == null)
			return "";
		String strTemp = certEntry.getIssuer();
		// int pos = 0;
		// String[] strTemps = strTemp.split(",");
		// for ( int x = 0; x < strTemps.length; x++ ) {
		// if ( (pos = strTemps[x].toUpperCase().indexOf("CN=")) != -1 ) {
		// strTemp = strTemps[x].substring(pos+3);
		// break;
		// }
		// }
		return "颁发者：" + strTemp;
	}

	@SuppressLint("SimpleDateFormat")
	public String getTime() {
		if (certEntry == null)
			return "";
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd");
		return "有效期：" + time.format(certEntry.getNotBefore()) + "到"
				+ time.format(certEntry.getNotAfter());
	}
}
